/*************************************************************************
 *  Copyright © 2023-2030 FXB CO.,LTD. All rights reserved.
 *------------------------------------------------------------------------
 *  公司：DefaultCompany
 *  项目：UPMProject
 *  文件：PackagePathManage.cs
 *  作者：Administrator
 *  日期：2025/2/13 10:2:49
 *  功能：Nothing
*************************************************************************/

using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEngine;

namespace SVNPackageManager.Runtime
{
    public class PackagePathManage
    {
        /// <summary>
        /// 从此处拷贝工具目录
        /// </summary>
        public static string LocalPackagePath
        {
            get
            {
                var assembly = Assembly.GetExecutingAssembly();

                string path = "";

#if UNITY_EDITOR
                var pInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(assembly);
                if (pInfo == null)
                    return null;

                path = Path.GetFullPath(pInfo.assetPath);
#endif

                path = path.Replace('\\', '/');

                return path;
            }
        }

        /// <summary>
        /// 获取当前包的资源路径
        /// </summary>
        public static string PackageResourcePath
        {
            get
            {
                var assembly = Assembly.GetExecutingAssembly();

                string path = "";
#if UNITY_EDITOR
                var pInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(assembly);
                if (pInfo == null)
                    return null;
                path = pInfo.assetPath.Replace('\\', '/');
#endif
                return path;
            }
        }

        public static string LocalPackageParentPath
        {
            get
            {
                var localPackagePath = LocalPackagePath;

                // 获取父级目录的路径
                string parentPath = Path.GetDirectoryName(localPackagePath);

                return parentPath;
            }
        }

        public static string SVNClientPath
        {
            get
            {
                var localPackagePath = LocalPackagePath;

                return Path.Combine(localPackagePath, "Plugins/SVNClient/Windows/svn.exe");
            }
        }

        public static string ScopedRegistryConfigPath
        {
            get
            {
                var localPackagePath = PackageResourcePath;

                localPackagePath = Path.Combine(localPackagePath, $"Resources/ScopedRegistryConfig.asset");

                localPackagePath = localPackagePath.Replace('\\', '/');

                return localPackagePath;
            }
        }
    }
}


